<template>
	<view>
		<view class="add-task-feedback main-basic-box">

			<!-- <van-field label="平台名称" :value="name" @change="name = $event.detail" placeholder="请输入" input-align="right"
				clearable>
			</van-field> -->
			<picker mode="selector" :range="clueArr" range-key="name" @change="clueChange">
				<van-field label="平台名称" readonly input-align="right">
					<template slot="button">
						<view style="color: #8A8F99"> {{name ? name : '请选择'}} <van-icon name="arrow"
								color="#BEBFC2"></van-icon> </view>
					</template>
				</van-field>
			</picker>

			<van-field label="平台账号" :value="account" @change="account = $event.detail" placeholder="请输入"
				input-align="right" clearable>
			</van-field>
			<van-field label="笔记链接" :value="linkurl" @change="linkurl = $event.detail" placeholder="请输入"
				input-align="right" clearable>
			</van-field>
			<view class="add-title">笔记截图</view>
			<c-upload :imgs="imgList" :maxNum="5" @delImg="delImg" @addSuccess="addImg"></c-upload>
		</view>
		<view class="main-basic-btn">
			<van-button block color="#4078E5" @click="submit">提交</van-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgList: [], //笔记截图
				name: '', //平台名称
				account: '', //平台账号
				linkurl: '', //笔记链接
				clueArr: [],
			};
		},
		onLoad(e) {
			if (e.pid) {
				this.project_id = e.pid
			}
			this.getclueSourse()
		},
		methods: {
			getclueSourse() {
				this.$api
					.requst('/gwc/orders/clue_sources', {}, )
					.then((res) => {
						this.clueArr = res.data
					})
			},
			clueChange(e) {
				this.name = this.clueArr[e.detail.value].name
			},
			delImg(index) {
				this.imgList.splice(index, 1)
			},
			addImg(url) {
				this.imgList.push(url)
			},
			async submit() {
				uni.showLoading({
					title: '数据提交中...'
				})
				let ids = []
				// 评价文件
				for (let i = 0; i < this.imgList.length; i++) {
					let fid = await this.$api.requestUploadQNY(this.imgList[i])
					ids.push(fid.asset_id)
				}
				let list = {
					project_id: this.project_id,
					order_type: 2,
					payload: {
						file: ids.join(','),
						pl_name: this.name,
						pl_account: this.account,
						link: this.linkurl
					},
				}
				this.$api
					.requst('/gwc/orders/create', list, 'POST')
					.then((res) => {
						this.$api.showError('提交成功！')
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)

					})
			}
		}
	}
</script>

<style scoped lang="scss">
	.add-task-feedback {
		margin-top: 32rpx;

		.add-title {
			font-size: 30rpx;
			color: #161616;
			padding-top: 36rpx;
			padding-bottom: 8rpx;
		}
	}

	::v-deep .van-cell {
		padding: 32rpx 0 !important;
	}

	::v-deep .van-field__label {
		font-size: 30rpx !important;
		color: #161616 !important;
	}

	::v-deep .van-cell:after {
		left: 0 !important;
		right: 0 !important;
	}
</style>